import java.util.Arrays;
import java.util.Comparator;

class Student {
    public String name;
    public int age;
    public double score;
    public Student(String name,int age,double score){
        this.name=name;
        this.age=age;
        this.score=score;
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
class AgeComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}
class ScoreComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return (int)(o1.score-o2.score);
    }
}
public class TestDemo1 {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0]=new Student("zhangsan",18,60);
        students[1]=new Student("lisi",22,100);
        students[2]=new Student("wangwu",20,85);
        AgeComparator ageComparator = new AgeComparator();
        ScoreComparator scoreComparator = new ScoreComparator();
        System.out.println("排序前:"+ Arrays.toString(students));
        Arrays.sort(students,scoreComparator);
        System.out.println("排序后:"+ Arrays.toString(students));
    }
}
